package com.ftd.model;

import org.hibernate.annotations.Table;
import org.springframework.stereotype.Component;

import javax.persistence.Entity;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;

/**
 * Created by apple on 2016/12/7.
 */
@Component
public class Book  implements Serializable {
    private int bookId;
    private String bookName;
    private int bookCount;
    private Date createTime;
    private Set<User> users;

    public Book(){

    }

    public int getBookId() {
        return bookId;
    }

    public void setBookId(int bookId) {
        this.bookId = bookId;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public int getBookCount() {
        return bookCount;
    }

    public void setBookCount(int bookCount) {
        this.bookCount = bookCount;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Set<User> getUsers() {
        return users;
    }

    public void setUsers(Set<User> users) {
        this.users = users;
    }

    public static class Builder{
        private String bookName = null;
        private int bookCount = 0;
        private Set<User> users = null;

        public Builder(String bookName){
            this.bookName = bookName;
        }
        public Builder bookCount(int count){
            this.bookCount = count;
            return this;
        }
        public Builder users(Set<User> list){
            this.users = list;
            return this;
        }
        public Book build(){
            return new Book(this);
        }

    }
    public Book(Builder b){
        this.bookCount = b.bookCount;
        this.bookName = b.bookName;
        this.users = b.users;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Book book = (Book) o;

        if (bookId != book.bookId) return false;
        if (bookCount != book.bookCount) return false;
        if (bookName != null ? !bookName.equals(book.bookName) : book.bookName != null) return false;
        if (createTime != null ? !createTime.equals(book.createTime) : book.createTime != null) return false;
        return users != null ? users.equals(book.users) : book.users == null;

    }

    @Override
    public int hashCode() {
        int result = bookId;
        result = 31 * result + (bookName != null ? bookName.hashCode() : 0);
        result = 31 * result + bookCount;
        result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
        result = 31 * result + (users != null ? users.hashCode() : 0);
        return result;
    }
}
